package com.atguigu.gmall.order.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.order.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//api/order/auth/submitOrder?tradeNo=199ff2d666c44b6ba47a43cc3fe75006
@RequestMapping("/api/order")
@RestController
public class OrderSubmitController {


    @Autowired
    OrderInfoService orderInfoService;



    /**
     * 提交订单
     * @param tradeNo
     * @param orderInfo
     * @return
     */
    @PostMapping("/auth/submitOrder")
    public Result submitOrder(@RequestParam("tradeNo") String tradeNo,
                              @RequestBody OrderInfo orderInfo){

        //1、生成订单
        OrderInfo submitOrder = orderInfoService.submitOrder(orderInfo,tradeNo);

        //2、前端不能接受过大的数字。损失精度。返回的orderId是一个字符串
        return Result.ok(submitOrder.getId()+"");
    }

}
